package cn.itsource.itsource.controller;

import ch.qos.logback.core.joran.action.ActionConst;
import cn.itsource.itsource.query.DepartmentQuery;
import cn.itsource.itsource.domain.Department;
import cn.itsource.itsource.service.IDepartmentService;
import cn.itsource.itsource.util.AjaxResult;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/dept")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;




    @PostMapping("/batchdel")
    @ResponseBody
    public AjaxResult batchDel(@RequestBody List<Long> ids){



        return departmentService.batchDel(ids);
    }

    @PostMapping("/saveorupdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(@RequestBody Department dept){

        return departmentService.saveOrUpdate(dept);
    }

    /**
     * 查询部门列表 以级联的方式进行返回
     * @return
     */

    @GetMapping("/treedept")
    @ResponseBody
    public AjaxResult treeDept(){
        return departmentService.treeDept();
    }


    @GetMapping("/findall")
    @ResponseBody
    public AjaxResult findAll(){
        AjaxResult result = AjaxResult.success("操作成功");
        result.setData(departmentService.findAll());
        return result;


    }

    @PostMapping("/save")
    @ResponseBody
    public AjaxResult save(Department department){

        return departmentService.save(department);


    }
    //@RequestBody 当是前后端分离项目时 前端传到后台而且是用对象接收时 必须加上此注解
    @PostMapping("/pagelist")
    @ResponseBody
    public AjaxResult pageList(@RequestBody  DepartmentQuery query){

         return departmentService.pageList(query);



    }



}
